package com.baba.vote.controller;

import com.baba.vote.common.OperReturnDto;
import com.baba.vote.dao.HtmlLogMapper;
import com.baba.vote.pojo.HtmlLog;
import com.baba.vote.util.QRCodeUtils;
import com.google.zxing.WriterException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author moxinHuoHuo
 * @create 2020/4/17 上午1:41
 */
@RestController
@RequestMapping("/system")
@Api(value = "系统相关接口")
@Slf4j
public class SystemController {


  @Autowired
  private HtmlLogMapper htmlLogMapper;

  @GetMapping
  @ApiOperation("获取当前前端跳转投票页面地址")
  public OperReturnDto get() {

    List<HtmlLog> all = htmlLogMapper.findAll();

    HtmlLog htmlLog;
    if (all.isEmpty()) {
      htmlLog = new HtmlLog();
    } else {
      htmlLog = all.get(0);
    }

    return OperReturnDto.formaterSuccess(htmlLog.getEntranceUrl());
  }

  @PostMapping("设置前端跳转投票页面地址")
  public OperReturnDto set(@RequestParam String url) {
    HtmlLog htmlLog = new HtmlLog();
    htmlLog.setEntranceUrl(url);

    htmlLogMapper.insert(htmlLog);

    return OperReturnDto.formaterSuccess();
  }

}
